package org.springblade.modules.demo.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import liquibase.pro.packaged.O;
import liquibase.pro.packaged.S;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.map.HashedMap;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.modules.demo.service.HomePageProcessingService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 后台首页对应接口Controller层
 *
 *
 *
 *
 * */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("blade-demo/homepageprocessing")
public class HomePageProcessingController {

	private final HomePageProcessingService homePageProcessingService;


	/**
	 * 13秒
	 *  交易次数 实扣金额 卡码用户数量  客单价  同比 环比  list返回
	 * 測試接口
	 */
	@GetMapping("/list1")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入simp101001")
	public R list1(@ApiIgnore @RequestParam Map<String, Object> dtmExpDataSum, Query query)
	{

		log.info("首页处理");
		Map<String,Object>map=new HashedMap();
		List<Map<String, Object>> list = new ArrayList<>();
		map=homePageProcessingService.tradeCountMap(0);
		log.info("首页处理交易次数同比和环比:"+map);
		list.add(map);

		map=homePageProcessingService.realTicketPriceMap(0);
		log.info("首页处理实扣金额同比和环比:"+map);
		list.add(map);

		map=homePageProcessingService.cardCountMap(0);
		log.info("首页处理票卡使用量同比和环比:"+map);
		list.add(map);


		map=homePageProcessingService.unitPriceMap(0);
		log.info("首页处理客单价同比和环比:"+map);
		//这个偷懒根据上面几个算的 所以一定要最后调用
		list.add(map);

		//获取前7天的 同比环比啥的
		map=homePageProcessingService.tradeCountMap(1);
		log.info("首页处理近一周交易次数同比和环比:"+map);
		list.add(map);
		map=homePageProcessingService.realTicketPriceMap(1);
		log.info("首页处理近一周实扣金额同比和环比:"+map);
		list.add(map);

		map=homePageProcessingService.cardCountMap(1);
		log.info("首页处理近一周票卡使用量同比和环比:"+map);
		list.add(map);


		//这个偷懒根据上面几个算的 所以一定要最后调用

		map=homePageProcessingService.unitPriceMap(1);
		log.info("首页处理近一周客单价同比和环比:"+map);
		list.add(map);
		log.info("查询接口检查："+list);
		return R.data(list);

	}




	/**
	 *  一周数据   47秒！  改造后 也要20多秒  在前端把超时时间从10秒改成30秒了 先测试数据
	 * 測試接口
	 */
	@GetMapping("/list2")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入simp101001")
	public R list2(@ApiIgnore @RequestParam Map<String, Object> dtmExpDataSum, Query query)
	{
		log.info("首页一周数据处理");
		List<Map<String, Map<String, String>>> list = new ArrayList<>();
		list.add(homePageProcessingService.GetWeekData(1));

//	long StartTime = System.currentTimeMillis(); 	// 1、开始时间
//	long endTime = System.currentTimeMillis(); 	// 2、结束时间
//	float time=   (endTime-StartTime)/1000;		//秒数

		log.info("查询接口检查list2："+list);
		return R.data(list);
	}



	/**
	 * 上传原始数据 和昨日消费数据处理情况 以及挂起数据分布
	 * 測試接口
	 */
	@GetMapping("/list3")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入simp101001")
	public R list3(@ApiIgnore @RequestParam Map<String, Object> dtmExpDataSum, Query query)
	{
		log.info("首页原始数据");
		List<Map<String,  String>> list = new ArrayList<>();
		list.add(homePageProcessingService.GetUploadedRawData());
		list.add(homePageProcessingService.GetYesterdayDataProcessing());
		list.add(homePageProcessingService.GetPendingDataDistribution());

		//拿到了开始拼接 处理逻辑写这里 是为了以后可能的拆分接口
//		Map<String,Object>map=new HashedMap();
//		Map<String,String>map1;
//		map1=homePageProcessingService.GetUploadedRawData();
//		map.put("GetUploadedRawData",map1);
//		map1=homePageProcessingService.GetYesterdayDataProcessing();
//		map.put("GetYesterdayDataProcessing",map1);
//		map1=homePageProcessingService.GetPendingDataDistribution();
//		map.put("GetPendingDataDistribution",map1);

		return R.data(list);
	}




}
